﻿CREATE TABLE [dbo].[purchase_Item] (
    [PurchaseId]                         BIGINT           IDENTITY (1, 1) NOT NULL,
    [PurchaseHashCode]                   NVARCHAR (8)     DEFAULT ([dbo].[RandString]((8))) NOT NULL,
    [UserId]                             UNIQUEIDENTIFIER NOT NULL,
    [Value]                              NVARCHAR (16)    NOT NULL,
    [BookId]                             UNIQUEIDENTIFIER NOT NULL,
    [UTCCreateDate]                      DATETIME         DEFAULT (getutcdate()) NOT NULL,
    [PurchaseStatusId]                   SMALLINT         NULL,
    [AuthecationDate]                    DATETIME         NULL,
    [AuthecationCode]                    NVARCHAR (32)    NULL,
    [AuthecationError]                   NVARCHAR (32)    NULL,
    [AuthecationErrorDescription]        NVARCHAR (MAX)   NULL,
    [AuthecationErrorInfo]               NVARCHAR (MAX)   NULL,
    [AuthecationTokenDate]               DATETIME         NULL,
    [AuthecationTokenAccessToken]        NVARCHAR (MAX)   NULL,
    [AuthecationTokenError]              NVARCHAR (32)    NULL,
    [AuthecationTokenErrorInfo]          NVARCHAR (MAX)   NULL,
    [PaymentRequestDate]                 DATETIME         NULL,
    [PaymentRequestStatus]               NVARCHAR (50)    NULL,
    [PaymentRequestRequestId]            NVARCHAR (MAX)   NULL,
    [PaymentRequestError]                NVARCHAR (32)    NULL,
    [PaymentRequestErrorInfo]            NVARCHAR (MAX)   NULL,
    [PaymentRequestContract]             NVARCHAR (MAX)   NULL,
    [PaymentRequestRecipientIdentified]  NVARCHAR (MAX)   NULL,
    [PaymentRequestRecipientAccountType] NVARCHAR (MAX)   NULL,
    [PaymentProcessDate]                 DATETIME         NULL,
    [PaymentProcessStatus]               NVARCHAR (50)    NULL,
    [PaymentProcessError]                NVARCHAR (32)    NULL,
    [PaymentProcessErrorInfo]            NVARCHAR (MAX)   NULL,
    [PaymentProcessPaymentId]            NVARCHAR (MAX)   NULL,
    [PaymentProcessInvoiceId]            NVARCHAR (MAX)   NULL,
    [PaymentProcessPayer]                NVARCHAR (MAX)   NULL,
    [PaymentProcessPayee]                NVARCHAR (MAX)   NULL,
    [PaymentProcessCreditAmount]         DECIMAL (8, 2)   NULL,
    CONSTRAINT [PK_UserPurchase] PRIMARY KEY CLUSTERED ([PurchaseId] ASC),
    CONSTRAINT [FK_purchase_Item_text_Book] FOREIGN KEY ([BookId]) REFERENCES [dbo].[text_Book] ([BookId]),
    CONSTRAINT [FK_UserPurchase_PurchaseStatus] FOREIGN KEY ([PurchaseStatusId]) REFERENCES [dbo].[purchase_Status] ([StatusId]),
    CONSTRAINT [FK_UserPurchase_User] FOREIGN KEY ([UserId]) REFERENCES [dbo].[user_User] ([UserId]),
    CONSTRAINT [IX_UserPurchase] UNIQUE NONCLUSTERED ([PurchaseId] ASC)
);





